# 增加create
str_1 = "a风"
str_2 = "2b"
str_1 += str_2
str_3 = str_1 + str_2
print(str_1, str_2, str_3)

# 检索retrieve
# find/index:find找不到子串返回-1,index报错
str_find = str_3.find("b")
print(str_find)
# startswith/endswith:
str_startswith = str_3.startswith("a")
str_endswith = str_3.endswith("a")
print(str_startswith, str_endswith)
# 索引[:]
str_4 = str_3[1:3]
print(str_4)

# 更新update
# replace替换
str_replace = str_3.replace("a", "tt wend")
print(str_replace)
# split分割
str_split = str_replace.split(" ")
print(str_split)
# join合并
str_join = "_".join(str_split)
print(str_join)

# 删除delete
# strip/lstrip/rstrip
'''
 '删除内容：头尾字符、空白符(包括\n、\r、\t、\' \'，即：换行、回车、制表符、空格)\n'
 '只会删除头和尾的字符，中间的不会删除'''

str_5 = "  努力 写 作业 "
str_strip_1 = str_5.strip()
str_strip_2 = str_5.strip(' ')
str_strip_3 = str_5.strip('业 努')
print(str_5)
print(str_strip_1)
print(str_strip_2)
print(str_strip_3)
print('________________________')

# %/format字符串的格式化输出
# 按传入参数的默认顺序
print("一个{}有十几个{}".format('幼儿园', '扛把子'))
# 按传入参数的默认顺序
print("{0}要是打人，{1}就打{0}".format("你", "我"))
# 按关键词参数
print("{city}是{nickname}".format(nickname="泉城", city="济南"))
# 按变量
city = "济南"
nickname = "泉城"
print(f"你听过{city}是{nickname}吗？")
# 处理浮点数
print("{:.3f}".format(3.999999))

# 读取并写入文件
original_file = open("第二周_第二节tmp.py", "r", encoding="utf-8")
the_new_file = open("第二周_第二节.py", "w", encoding="utf-8")
the_new_file.write(original_file.read())
the_new_file.close()
original_file.close()
